package LeetCode.leetcode19;

public class Review1 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
            if (head == null) return null;
            ListNode virtualNode = new ListNode();
            virtualNode.next = head;
            ListNode slow = virtualNode;
            ListNode fast = head;
        for (int i = 0; i < n; i++) {
            fast = fast.next;
        }
        while (fast != null){
            slow = slow.next;
            fast = fast.next;
        }
        slow.next = slow.next.next;
        return virtualNode.next;
    }
}
